package com.letv.android.client.episode.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.letv.android.client.episode.widget.RelateItem;
import com.letv.android.young.client.R;
import com.letv.core.bean.RelateSetBean;
import com.letv.core.bean.VideoRelatedListBean;

public class HalfRelatedAdapter extends BaseAdapter{
	
	private static final String TAG = HalfRelatedAdapter.class.getSimpleName();
	private VideoRelatedListBean mRelatedBeanArray;
	private Context mContext;
	private long curID;
	private boolean isNormalVideo;
	private boolean isVipTab;
	
	public HalfRelatedAdapter(Context context, VideoRelatedListBean relatedBeanArray){
		mContext = context;
		mRelatedBeanArray = relatedBeanArray;
	}
	
	public void setIsNormalVideo(boolean isNormalVideo){
		this.isNormalVideo = isNormalVideo;
	}
	
	@Override
	public int getCount() {
		return mRelatedBeanArray.size();
	}

	@Override
	public Object getItem(int position) {
		return mRelatedBeanArray.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public int getItemViewType(int position) {
		return mRelatedBeanArray.get(position).type;
	}
	
	public void setCurID(long curID){
		this.curID = curID;
	}
	
	public void setIsVipTab(boolean isVipTab){
		this.isVipTab = isVipTab;
	}
	
	public int getViewTypeCount() {
		return VideoRelatedListBean.VIDEO_RELATED_COUNT;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		int type = getItemViewType(position);
		RelateItem relateItem;
		RelateSetBean relatedBean = mRelatedBeanArray.get(position);
		
			switch (type) {
				case VideoRelatedListBean.RELATE_TITLE_TYPE: 
				case VideoRelatedListBean.RECT_TITLE_TYPE:
					if (convertView == null){
						convertView = LayoutInflater.from(mContext).
								inflate(R.layout.letv_detail_half_play_relate_title, null);
					}
					
					TextView textView = (TextView) convertView
							.findViewById(R.id.detail_half_related_like);
					if (textView != null) {
						if (relatedBean.type == VideoRelatedListBean.RELATE_TITLE_TYPE) {
							textView.setText(R.string.detail_half_player_relate);
						} else {
							if (!isVipTab){
								textView.setText(R.string.detail_half_player_relate_youlike);
							}else{
								textView.setText(R.string.detail_half_player_relate_youlike_vip);
							}
						}
					}
					break;
				case VideoRelatedListBean.SELF_VIDEO_TYPE:
				case VideoRelatedListBean.CMS_CONTENT_TYPE:
				case VideoRelatedListBean.RELATE_CONTENT_TYPE:
				case VideoRelatedListBean.RECT_CONTENT_TYPE:
					if (convertView == null){
						convertView = LayoutInflater.from(mContext).
								inflate(R.layout.letv_detail_half_play_related_view_item_playlibs, null);
					}
					
					if (convertView instanceof RelateItem) {
						relateItem = (RelateItem) convertView;
						relateItem.bindView(relatedBean);
						relateItem.setItemIsSelect(curID);
					}
					break;
			default:
				break;
			}
		
		return convertView;
	}

}
